package com.ptswitch.material.dao.impl;

import java.util.List;

import org.hxzon.project.SpringJdbcDao;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import com.ptswitch.material.model.material.Bom;

@Repository
public class BomDao extends SpringJdbcDao {
    private static final RowMapper<Bom> bomMapper = buildBeanRowMapper(Bom.class);
    private static final String SelectCommon = "select id,code,fileName,createTime,updateTime ";
    private static final String FromTable = " from bom ";
    private static final String DefaultOrderBy = " order by code asc,version desc";

    public Bom findById(String id, int init) {
        String where = " where id=:id ";
        String fullSql = SelectCommon + FromTable + where;
        SqlParameterSource paramSource = buildMapParams("id", id);
        return super.queryOne(fullSql, paramSource, bomMapper);
    }

    public Bom findByCodeAndVersion(String code, String version) {
        String where = " where code=:code and version=:version ";
        String fullSql = SelectCommon + FromTable + where;
        SqlParameterSource paramSource = buildMapParams("code", code,"version", version);
        return super.queryOne(fullSql, paramSource, bomMapper);
    }

    public void saveEx(Bom model) {
        ;
    }

//  public List<Bom> findAll(boolean initialize);

    public void deleteAll() {
        ;
    }

    public Bom findById(String id) {
        return null;
    }

    public void delete(Bom bom) {
        ;
    }

    public void save(Bom bom) {
        ;
    }

    public List<Bom> findAll() {
        return null;
    }

    public List<Bom> findAll(long first, long size) {
        String fullSql = SelectCommon + FromTable + DefaultOrderBy + " limit :first,:size";
        return super.queryList(fullSql, buildMapParams("first", first, "size", size), bomMapper);
    }

    public long countAll() {
        String fullSql = "select count(id) from bom";
        return super.count(fullSql, buildMapParams());
    }

    public List<Bom> findLike(String like, long first, long size) {
        return null;
    }

    public long countLike(String like) {
        return 0;
    }

}
